package com.tuyan.aixiang.component;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tuyan.aixiang.R;
import com.tuyan.aixiang.activity.web.WebActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MsgCategoryItem extends RelativeLayout {


    @BindView(R.id.ll_count_wrapper)
    LinearLayout llCountWrapper;

    @BindView(R.id.tv_count)
    TextView tvCount;

    @BindView(R.id.iv_icon)
    ImageView ivIcon;

    @BindView(R.id.tv_title)
    TextView tvTitle;


    public MsgCategoryItem(Context context) {
        this(context, null);
    }

    public MsgCategoryItem(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MsgCategoryItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View contentView = LayoutInflater.from(context).inflate(R.layout.msg_category_item, this);
        ButterKnife.bind(contentView, this);
    }

    public void setUp(int title, int icon, String url) {
        tvTitle.setText(getResources().getString(title));
        ivIcon.setImageResource(icon);
        setOnClickListener(v -> {
            WebActivity.open(getContext(), url);
        });
    }

    public void setUpIgnore() {
        setVisibility(INVISIBLE);
    }

    public void setCount(int count) {
        if (count == 0) {
            llCountWrapper.setVisibility(GONE);
        } else {
            llCountWrapper.setVisibility(VISIBLE);

            if (count > 999) {
                tvCount.setText("999+");
            } else {
                tvCount.setText(count + "");
            }

        }

    }

}
